package Units;

import java.util.ArrayList;

import Game.GameModel;
import Game.scene.Stage;

public class EnemyTank extends GameModel{

	private float vel = 0;
	private float ang = 90;
	private float acel = 8;
	private float maxSpeed = 20;
	public ArrayList<CannonBall> bulletList = new ArrayList<CannonBall>();
	private long cooldown = 5000;
	private long lastShoot = 0;
	private String inimigoName;
	private long creationTime;
	
	public EnemyTank(float x, float y, float z, String modelPath,
			String texturePath) {
		super(x, y, z, modelPath, texturePath);
		creationTime = System.currentTimeMillis();
		inimigoName = "Inimigo"+creationTime;
		parentName = inimigoName;
	}
	
	public void aim(Tank tank) {
		
//		rotateY = (float)Math.toDegrees(Math.atan2(tank.x-x, tank.z -z));
		modelList.get(0).rotateY = (float)Math.toDegrees(Math.atan2(tank.x-x, tank.z -z));// - rotateY;
		modelList.get(1).rotateY = (float)Math.toDegrees(Math.atan2(tank.x-x, tank.z -z));// - rotateY;
		
//		System.out.println(rotateY + modelList.get(0).rotateY);
	}
	
	
	public void Shoot(Tank tank){
		
		if(System.currentTimeMillis() - creationTime > 5000)
		if(System.currentTimeMillis() - lastShoot> cooldown){
			Stage.addChild(Factory.newBullet(x, y, z, rotateY+modelList.get(0).rotateY, inimigoName));
			lastShoot = System.currentTimeMillis();
		}
	}
	
	@Override
	public void Update(long diftime) {
		
//		if(vel < 15)
//			vel += diftime * acel / 1000.0f;
//		
//		double radians = Math.toRadians(this.rotateY);
//		x += ((float)Math.cos((double)radians) * vel) * diftime / 1000;
//		z += (((float)Math.sin((double)radians) * vel) * diftime / 1000)*-1;
	}
	
}
